<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Save Data</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<style>
body {
	display: block;
	line-height: 1.5;
	font-size: 75%;
	background: white;
	font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;
	text-align: center;
}
a {
	font: 12px Arial;
	color: #ac9095;
}

#msgerreur {
	color: red;
}
</style>
<script type="text/javascript">
	var id = 0;
	$(document)
			.ready(
					function() {
						var f = $('form'), a = $('a'), i = $('input[type=text]'),
							s = $('select'),  p = $('input[type=password]'), t = $('textarea');
						$('#save').click(
								function() {
									var o = {};
									var separateur = ','
									var jsontxt = "[ ";
									$('tr').each(function(index){

									$(this).find('td input[type=text]').each(function() {
										o[this.name] = $(this).val();
									});
									$(this).find('td select').each(function() {
										o[this.name] = $(this).val();
									});
									$(this).find('td input[type=password]').each(function() {
										o[this.name] = $(this).val();
									});
									if(!jQuery.isEmptyObject(o)){
										if(index < ($('tr').length - 1))
											jsontxt += JSON.stringify(o) + separateur;
										else
											jsontxt += JSON.stringify(o);
									}
									console.log(index);
									});
									jsontxt += " ]";
									$('a').attr('href', 'data:application/x-json;base64,' + btoa(jsontxt)).show();
								});
						createTableData();
					});

	function getJSON() {
		var data = {};
		datatxt = '[ {"id":"0","agence":"Ecotour","officeid":"AAAA","url":"http://ecotour/fo/air/search.do","login":"","password":"","environnement":"Local","site":"fo","flux":"air"},{"id":"1","agence":"Karavel","officeid":"AAAA","url":"http://karavel/fo/air/search.do","login":"","password":"","environnement":"Local","site":"fo","flux":"air"},{"id":"2","agence":"Tourcom","officeid":"PARTQ2858","url":"http://tourcom/fo/air/search.do?OFFICEID=PARTQ2858","login":"","password":"","environnement":"Local","site":"fo","flux":"air"},{"id":"3","agence":"Manor","officeid":"PARMM28AA","url":"http://manor/fo/air/search.do?OFFICEID=PARMM28AA","login":"","password":"","environnement":"Local","site":"fo","flux":"air"},{"id":"4","agence":"Aircorsica, CCM Airlines","officeid":"AJAXK08AC","url":"http://ccm/fo/airhotelccm/search_CCM.do?OFFICEID=AJAXK08AC","login":"","password":"","environnement":"Local","site":"fo","flux":"airhotel"},{"id":"5","agence":"Afat Voyages","officeid":"TLSFT28AA","url":"http://afatvoyages/fo/mixdisplay/search.do?OFFICEID=TLSFT28AA","login":"","password":"","environnement":"Local","site":"fo","flux":"mixdisplay"},{"id":"6","agence":"Afat Voyages","officeid":"TLSFT28AA","url":"http://afatvoyages/fo/airhotel/search.do?OFFICEID=TLSFT28AA","login":"","password":"","environnement":"Local","site":"fo","flux":"airhotel"},{"id":"7","agence":"Afat Voyages","officeid":"TLSFT28AA","url":"http://afatvoyages/fo/car/search.do?OFFICEID=TLSFT28AA","login":"","password":"","environnement":"Local","site":"fo","flux":"car"},{"id":"8","agence":"Afat Pro","officeid":"002FT28AA","url":"http://afataffaires/fo/mixdisplay-easypro/search.do?OFFICEID=002FT28AA","login":"","password":"","environnement":"Local","site":"fo","flux":"mixdisplay"},{"id":"9","agence":"Afat Voyages","officeid":"TLSFT28AA","url":"http://afatvoyages/fo/hotel/search.do?OFFICEID=TLSFT28AA","login":"","password":"","environnement":"Local","site":"fo","flux":"hotel"},{"id":"10","agence":"Afat - Agence Corse","officeid":"AJAFT2802","url":"http://afatvoyages/fo/mixdisplay/search.do?OFFICEID=AJAFT2802","login":"","password":"","environnement":"Local","site":"fo","flux":"mixdisplay"},{"id":"11","agence":"Selectour","officeid":"TLSFT28AA","url":"http://selectour/fo/mixdisplay/search.do?OFFICEID=TLSFT28AA","login":"","password":"","environnement":"Local","site":"fo","flux":"mixdisplay"},{"id":"12","agence":"Selectour","officeid":"TLSSR28AK","url":"http://selectour/fo/mixdisplay/search.do?OFFICEID=TLSSR28AK","login":"","password":"","environnement":"Local","site":"fo","flux":"mixdisplay"},{"id":"13","agence":"Selectour Pro","officeid":"001SR28AK","url":"http://selectourpro/fo/mixdisplay-easypro/search.do?OFFICEID=001SR28AK","login":"","password":"","environnement":"Local","site":"fo","flux":"mixdisplay"},{"id":"14","agence":"SelectourPro","officeid":"002SR28AK","url":"http://selectourpro/fo/mixdisplay-easypro/search.do?OFFICEID=002SR28AK","login":"","password":"","environnement":"Local","site":"fo","flux":"mixdisplay"},{"id":"15","agence":"Beinbeyond FR","officeid":"NCECD28BB","url":"http://beinbeyond/fo/air/search.do?OFFICE_ID=NCECD28BB&MODE=AIR&SEARCH_TYPE=&CSS=BLUE&request_locale=fr_FR","login":"","password":"","environnement":"Local","site":"fo","flux":"air"},{"id":"16","agence":"Beinbeyond EN","officeid":"NCECD28BB","url":"http://beinbeyond/fo/air/search.do?OFFICE_ID=NCECD28BB&MODE=AIR&SEARCH_TYPE=&CSS=BLUE&request_locale=en_GB","login":"","password":"","environnement":"Local","site":"fo","flux":"air"},{"id":"17","agence":"Beinbeyond ES","officeid":"NCECD28BB","url":"http://beinbeyond/fo/air/search.do?OFFICE_ID=NCECD28BB&MODE=AIR&SEARCH_TYPE=&CSS=BLUE&request_locale=es_ES","login":"","password":"","environnement":"Local","site":"fo","flux":"air"},{"id":"18","agence":"BeInBeyond","officeid":"NCECD28BB","url":"http://localhost:8080/fo/start/startup.do?OFFICE_ID=NCECD28BB&MODE=AIR&SEARCH_TYPE=&CSS=BLUE&request_locale=fr_FR","login":"","password":"","environnement":"Local","site":"fo","flux":"air"},{"id":"19","agence":"CarrefourVoyages","officeid":"004CL214E","url":"http://localhost.carrefourvoyages.fr/fo/mxcarrefour/search.do?OFFICE_ID=004CL214E&flux=air","login":"","password":"","environnement":"Local","site":"fo","flux":"mixdisplay"},{"id":"20","agence":"Carrefour Voyages B2B","officeid":"004CL214E","url":"http://localhost.carrefourvoyagesb2b.fr/fo/login/identification.do","login":"","password":"","environnement":"Local","site":"fo","flux":"mixdisplay"},{"id":"21","agence":"Carrefour Voyages","officeid":"003CL214E","url":"http://localhost.carrefourvoyages.fr/fo/railairhotelcarrefour/search.do?OFFICE_ID=003CL214E","login":"","password":"","environnement":"Local","site":"fo","flux":"railairhotel"},{"id":"22","agence":"Carrefour Voyages","officeid":"005CL214E","url":"http://localhost.carrefourvoyages.fr/fo/carcarrefour/search.do?OFFICE_ID=005CL214E","login":"","password":"","environnement":"Local","site":"fo","flux":"car"},{"id":"23","agence":"Carrefour Voyages","officeid":"002CL214E","url":"http://localhost.carrefourvoyages.fr/fo/hotelcarrefour/search.do?OFFICE_ID=002CL214E","login":"","password":"","environnement":"Local","site":"fo","flux":"hotel"},{"id":"24","agence":"Degriffe Voyages","officeid":"DEGRI1234","url":"http://degriffe/fo/airhotel/search.do?OFFICEID=DEGRI1234","login":"","password":"","environnement":"Local","site":"fo","flux":"airhotel"},{"id":"25","agence":"Boiloris","officeid":"BOIL12345","url":"http://boiloris/fo/airhotel/search.do?OFFICEID=BOIL12345","login":"","password":"","environnement":"Local","site":"fo","flux":"airhotel"},{"id":"26","agence":"Palmair","officeid":"PARA1288B","url":"http://localhost.palmair.fr/fo/air/search.do?OFFICEID=PARA1288B","login":"","password":"","environnement":"Local","site":"fo","flux":"air"},{"id":"27","agence":"Agence Chine Tourlsme","officeid":"PARA12430","url":"http://act/fo/air/search.do?OFFICEID=PARA12430","login":"","password":"","environnement":"Local","site":"fo","flux":"air"},{"id":"28","agence":"Amadeus e-travellers","officeid":"PAR1A2800","url":"http://easypro/fo/mixdisplay/search.do?OFFICEID=PAR1A2800","login":"","password":"","environnement":"Local","site":"fo","flux":"mixdisplay"},{   "agence":"Aircorsica, CCM Airlines - vol+Hotel -AJAXK08AC",   "url":"http://pp-ccm.amadeus.fr/airhotelccm/search_CCM.do?OFFICEID=AJAXK08AC","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"BeInBeyond - Recherche d\'un vol",   "url":"http://pp-b2c-n3.amadeus.fr/beinbeyond/start/startup.do?OFFICE_ID=NCECD28BB&MODE=AIR&SEARCH_TYPE=&CSS=BLUE&request_locale=fr_FR","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Ecotour - Recherche d\'un vol",   "url":"http://pp-ecotour.amadeus.fr/ecotour/air/search.do","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Agence Chine Tourlsme : Recherche d\'un vol",   "url":"http://pp-b2c-act.amadeus.fr/air/search.do?OFFICEID=PARA12430","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Tourcom - Recherche d\'un vol - PARTQ2858",   "url":"http://pp-b2c-tourcom.amadeus.fr/air/search.do?OFFICE_ID=PARTQ2858","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Tourcom - Recherche d\'un hôtel",   "url":"http://b2c-tourcom.amadeus.fr/hotel/search.do?OFFICE_ID=BIQTQ28AB","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Afat - Recherche d\'un vol+Hotel",   "url":"http://pp-b2c-afat.amadeus.fr/airhotel/search.do?OFFICEID=TLSFT28AA","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Afat - Vol train",   "url":"http://pp-b2c-afat.amadeus.fr/mixdisplay/search.do?OFFICEID=TLSFT28AA","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Afat Pro - Vol train",   "url":"http://pp-b2c-afatpro.amadeus.fr/easypro/mixdisplay-easypro/search.do?OFFICE_ID=002FT28AA","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Afat - Agence Corse - Vol train",   "url":"http://pp-b2c-afat.amadeus.fr/mixdisplay/search.do?OFFICEID=AJAFT2802","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Selectour - Vol train - TLSFT28AA",   "url":"http://pp-b2c-selectour.amadeus.fr/mixdisplay/search.do?OFFICEID=TLSFT28AA","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Selectour - Vol train - TLSSR28AA",   "url":"http://pp-b2c-selectour.amadeus.fr/mixdisplay/search.do?OFFICEID=TLSSR28AA","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Selectour Pro - Vol train",   "url":"http://pp-b2c-selectourpro.amadeus.fr/easypro/mixdisplay-easypro/search.do?OFFICEID=002SR28AK","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Carrefour Voyages - Vol train",   "url":"http://preproduction.vol.voyages.carrefour.fr/mxcarrefour/search.do?OFFICE_ID=004CL214E&flux=air","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Carrefour Voyages - Recherche d\'un véhicule",   "url":"http://preproduction.location-voiture.carrefour.fr/carcarrefour/search.do?OFFICE_ID=005CL214E","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Carrefour Voyages - Recherche d\'un vol/train + hotel",   "url":"http://preproduction.sejour-sur-mesure.voyages.carrefour.fr/railairhotelcarrefour/search.do?OFFICE_ID=003CL214E","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Carrefour Voyages - Recherche d\'un hôtel",   "url":"http://preproduction.hotel.voyages.carrefour.fr/hotelcarrefour/search.do?OFFICE_ID=002CL214E","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Amadeus e-travellers",   "url":"http://pp-e-travellers.amadeus.fr/mixdisplay/search.do?OFFICEID=PAR1A28BD","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Jaltour - Acceuil",   "url":"http://pp-b2c-n2.amadeus.fr/JalTour/accueil.do","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""},{   "agence":"Jaltour  - Administration",   "url":"http://pp-b2c-n2.amadeus.fr/JalTour/admIndex.do","officeid":"","id":"","login":"","password":"","environnement":"Pre-Production","site":"","flux":""}]';
		
		if(datatxt != null){
			data = JSON.parse(datatxt);
			return data;
		}
		/* $.getJSON('json/data.json', function(jsondata) {
			data = jsondata;
		}); */
		return data;
	}

	function createTableData() {
		var data = getJSON();
		var tablehtml = '';
		for(var i = 0; i < data.length; i++){
			tablehtml += '<tr>';
			tablehtml += createIdhtml(generateId());
			tablehtml += createEnvironnementhtml(data[i].environnement);
			tablehtml += createAgencehtml(data[i].agence);
			tablehtml += createSitehtml(data[i].site);
			tablehtml += createFluxhtml(data[i].flux);
			tablehtml += createOfficeidhtml(data[i].officeid);
			tablehtml += createUrlhtml(data[i].url);
			tablehtml += createLoginhtml(data[i].login)
			tablehtml += createPasswordhtml(data[i].password);
			tablehtml += '</tr>';
		}
		$('table tbody').append(tablehtml);
	}

	function createIdhtml(id){
		var idhtml = '<td>'
			idhtml +='<input type="text" name="id" value="'+id+'" disabled="disabled">'
			idhtml += '</td>';
		return idhtml;
	}
	
	function createEnvironnementhtml(environnement){
		var selected = 'selected="selected"';
		var environnementhtml = '<td><select name="environnement">';
		environnementhtml +='<option value="" ';
		if(environnement == '')
			environnementhtml += selected;
		environnementhtml +='>Environnement</option>';
		environnementhtml +='<option value="Local" ';
		if(environnement == 'Local')
			environnementhtml += selected;
		environnementhtml +='>Local</option>';
		environnementhtml +='<option value="Demo" ';
		if(environnement == 'Demo')
			environnementhtml += selected;
		environnementhtml +='>Demo</option>';
		environnementhtml +='<option value="Integration" ';
		if(environnement == 'Integration')
			environnementhtml += selected;
		environnementhtml +='>Integration</option>';
		environnementhtml +='<option value="Pre-Production" ';
		if(environnement == 'Pre-Production')
			environnementhtml += selected;
		environnementhtml +='>Pré-Production</option>';
		environnementhtml +='<option value="Production" ';
		if(environnement == 'Production')
			environnementhtml += selected;
		environnementhtml +='>Production</option>';
		environnementhtml +='</select></td>';
		return environnementhtml;
	}
	
	function createAgencehtml(agence){
		var agencehtml = '<td>';
		agencehtml += '<input type="text" name="agence" value="'+agence+'">';
		agencehtml += '</td>'; 
		return agencehtml;
	}
	
	function createSitehtml(site){
		var selected = 'selected="selected"';
		var sitehtml = '<td><select name="site">';
		sitehtml +='<option value=""';
		if(site == '')
			sitehtml += selected;
		sitehtml +='>Site</option>';
		sitehtml +='<option value="fo"';
		if(site == 'fo')
			sitehtml += selected;
		sitehtml +='>Front Office</option>';
		sitehtml +='<option value="bo"';
		if(site == 'bo')
			sitehtml += selected;
		sitehtml +='>Cardibox</option>';
		sitehtml +='<option value="eretailmgr"';
		if(site == 'eretailmgr')
			sitehtml += selected;
		sitehtml +='>Eretail Manager</option>';
		sitehtml +='<option value="ws"';
		if(site == 'ws')
			sitehtml += selected;
		sitehtml +='>WebService</option>';
		sitehtml +='</select></td>';
		return sitehtml;
	}
	
	function createFluxhtml(flux){
		var selected = 'selected="selected"';
		var fluxhtml = '<td><select name="flux">';
		fluxhtml += '<option value=""';
		if(flux == '')
			fluxhtml += selected;
		fluxhtml += '>Flux</option>';
		fluxhtml += '<option value="mixdisplay"';
		if(flux == 'mixdisplay')
			fluxhtml += selected;
		fluxhtml += '>MixDisplay</option>';
		fluxhtml += '<option value="air"';
		if(flux == 'air')
			fluxhtml += selected;
		fluxhtml += '>Air</option>';
		fluxhtml += '<option value="rail"';
		if(flux == 'rail')
			fluxhtml += selected;
		fluxhtml += '>rail</option>';
		fluxhtml += '<option value="hotel"';
		if(flux == 'hotel')
			fluxhtml += selected;
		fluxhtml += '>Hotel</option>';
		fluxhtml += '<option value="car"';
		if(flux == 'car')
			fluxhtml += selected;
		fluxhtml += '>Véhicule</option>';
		fluxhtml += '<option value="airhotel"';
		if(flux == 'airhotel')
			fluxhtml += selected;
		fluxhtml += '>AirHotel</option>';
		fluxhtml += '<option value="railairhotel"';
		if(flux == 'railairhotel')
			fluxhtml += selected;
		fluxhtml += '>RailAirHotel</option>';
		fluxhtml += '</select></td>';
		return fluxhtml;
	}
	
	function createOfficeidhtml(officeid){
		var officeidhtml = '<td>';
		officeidhtml +='<input type="text" name="officeid" value="'+officeid+'">';
		officeidhtml +='</td>';
		return officeidhtml;
	}
	
	function createUrlhtml(url){
		var urlhtml = '<td>';
		urlhtml +='<input type="text" name="url" value="'+url+'">';
		urlhtml +='</td>';
		return urlhtml;
	}
	
	function createLoginhtml(login){
		var loginhtml = '<td>';
		loginhtml +='<input type="text" name="login" value="'+login+'">';
		loginhtml +='</td>';
		return loginhtml;
	}
	
	function createPasswordhtml(password){
		var passwordhtml = '<td>';
		passwordhtml +='<input type="password" name="password" value="'+password+'">';
		passwordhtml +='</td>';
		return passwordhtml;
	}
	
	function validate(){
		var i = $('input[type=text]');
		var s = $('select');
		var msgerror = 'Vous devez saisir tous les champs obligatoires. <br>';
		var check = true;
		
		i.each(function(index) { 
			if($(this).val() == ''){
				if($(this)[index] == $('input[name="officeid"]')[index] && $('select[name="site"]').val() != 'fo' && $('select[name="site"]').val() != '' || $(this)[index] == $('input[name="login"]')[index]){
					return;
				}
				msgerror += 'Vous devez remplir le champs '+ this.name + ' n° '+index+'. <br>';
				check = false;
			}
		});
		s.each(function(index) { 
		    	if($(this).val() == ''){
		    		if($(this)[index] == $('select[name="flux"]')[index] && $('select[name="site"]').val() != 'fo' && $('select[name="site"]').val() != ''){
						return;
					}
					msgerror += 'Vous devez remplir le champs '+ this.name + ' n° '+index+'. <br>';
					check = false;
				}
		});
		if(!check){
			$('#msgerreur').html(msgerror);
			return false;
		}
		return true;
	}

	function generateId() {
		return id++;
	}

</script>
</head>
<body>
	<p id="msgerreur"></p>
	<div>
		<table>
			<tbody>
				<tr>
					<td>Id</td>
					<td>Environnement</td>
					<td>Agence de voyages</td>
					<td>Site</td>
					<td>Flux</td>
					<td>OfficeId</td>
					<td>url</td>
					<td>Login</td>
					<td>Mot de passe</td>
				</tr>
			</tbody>
		</table>
		<input type="button" id="save" value="Export data" />
		<a href="" style="display: none;">Download data</a>
	</div>
</body>
</html>